<template>
	<view class="content">
		<view class="menu-item">
			<view class="tab-item" :class="tabActive=='全部'?'active':''" @click="bindActive('全部')">全部</view>
			<view class="tab-item" :class="tabActive=='蓝灯单位'?'active':''" @click="bindActive('蓝灯单位')">蓝灯单位</view>
			<view class="tab-item" :class="tabActive=='黄灯单位'?'active':''" @click="bindActive('黄灯单位')">黄灯单位</view>
			<view class="tab-item" :class="tabActive=='红灯单位'?'active':''" @click="bindActive('红灯单位')">红灯单位</view>
		</view>
		<view class="info-block">
			<view class="sort-item">
				<view class="order-item" :class="orderActive==0?'active':''" @click="bindOrderActive(0)">项目进度排序</view>
				<view class="order-item" :class="orderActive==1?'active':''" @click="bindOrderActive(1)">更新时间排序</view>
			</view>
			<view class="tips" v-if="tabActive=='蓝灯单位'" style="background-color: #C5E0FB;">
				<image src="/static/project/blue.png" class="img"></image>
				<view class="text">“蓝灯”表示资金到位率在80%(含)以上，共计<text class="total">{{count}}</text>个单位。</view>
			</view>
			<view class="tips" v-if="tabActive=='黄灯单位'" style="background-color: #F7E6C8;">
				<image src="/static/project/yellow.png" class="img"></image>
				<view class="text">“黄灯”表示资金到位率在20%(含)至80%，共计<text class="total">{{count}}</text>个单位。</view>
			</view>
			<view class="tips" v-if="tabActive=='红灯单位'" style="background-color: #F1C7C8;">
				<image src="/static/project/red.png" class="img"></image>
				<view class="text"> “红灯”表示资金到位率在20%以下，共计<text class="total">{{count}}</text>个单位。</view>
			</view>
			<template v-if="list.length>0">
				<view class="info-item" v-for="(item,index) in list" :key="item.id">
					<view class="title-item">
						<view class="round" style="background-color: #FFA101;" v-if="item.statusText==='黄灯单位'"></view>
						<view class="round" style="background-color: #127DFF;" v-else-if="item.statusText==='蓝灯单位'">
						</view>
						<view class="round" style="background-color: #FE0000;" v-else-if="item.statusText==='红灯单位'">
						</view>
						<view class="name">{{index+1}}、{{item.departmentText}}</view>
					</view>
					<view class="progress-block">
						<view class="name-block">
							<view class="name"><text class="title">分类：</text>{{item.typeText}}</view>
							<!-- <view class="time">{{item.tasks}}万元</view> -->
						</view>
						<view class="name-block">
							<view class="name"><text class="title">完成比例：</text></view>
						</view>
						<progress :percent="item.taskCompletion" border-radius="20rpx" :stroke-width="8"
							activeColor="#0050FC" backgroundColor="#efefef"></progress>
						<view class="phase" v-if="item.taskCompletion<100&&item.taskCompletion>10"><text
								:style="'left:calc('+item.taskCompletion+'% - 80rpx)'">{{item.taskCompletion}}%</text>
						</view>
						<view class="phase" v-else-if="item.taskCompletion<=10"><text
								:style="'left:calc('+item.taskCompletion+'% - 10rpx)'">{{item.taskCompletion}}%</text>
						</view>
						<view class="phase" v-else-if="item.taskCompletion>=100"><text
								:style="'left:calc('+item.taskCompletion+'% - 200rpx)'">{{item.taskCompletion}}%</text>
						</view>
					</view>
					<view class="amount-list">
						<view class="amount-item">
							<view class="money">{{item.taskPlan}}万元</view>
							<view class="text">任务金额</view>
						</view>
						<view class="thread"></view>
						<view class="amount-item">
							<view class="money">{{item.completionFunds}}万元</view>
							<view class="text">完成金额</view>
						</view>
					</view>
				</view>
			</template>
			<view v-else style="text-align: center;">暂无数据</view>
			<!-- <view v-if="list.length>0&&!listConf.more" style="text-align: center;">没有更多了</view> -->
		</view>
	</view>
</template>

<script>
	import {
		getInvestmentListApi
	} from '@/api/financial.js'
	import {
		isMore
	} from '@/util/util.js'
	export default {
		data() {
			return {
				listConf: {
					page: 1,
					limit: 10,
					more: true,
				},
				tabActive: '全部',
				orderActive: 0,
				list: [],
				count: 0
			}
		},
		methods: {
			bindActive(item) {
				this.tabActive = item
				this.listConf.page = 1
				this.getList(true)
			},
			bindOrderActive(index) {
				this.orderActive = index
				this.listConf.page = 1
				this.getList(true)
			},
			getList(refresh = false) {
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				var data = new Date()
				let year = data.getFullYear()
				getInvestmentListApi({
					status: this.tabActive,
					sort: this.orderActive,
					year: year
				}).then(data => {
					uni.hideLoading()
					this.list = data.list1 || [];
					this.count = data.count
					// if (refresh) {
					// 	this.list = list;
					// } else {
					// 	this.list = [...this.list, ...list]
					// }
					// this.listConf.more = isMore(this.listConf.page, this.listConf.limit, data.count);
				}).catch(() => {
					uni.hideLoading()
				})
			}
		},
		// onReachBottom() {
		// 	if (this.listConf.more) {
		// 		this.listConf.page++;
		// 		this.getList()
		// 	}
		// },
		onLoad() {
			this.getList(true)
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		background: #fff;
		width: 100%;
		min-height: 100vh;

		.menu-item {
			width: 100%;
			height: 200rpx;
			background-color: #157EFE;
			display: flex;
			flex-direction: row;
			justify-content: space-around;
			color: #fff;

			.tab-item {
				margin-top: 30rpx;
				height: 60rpx;
				font-size: 30rpx;
			}

			.tab-item.active {
				font-size: 34rpx;
				font-weight: bold;
				margin-bottom: 10rpx;
				border-bottom: 6rpx solid #fff;
			}
		}

		.info-block {
			min-height: 80vh;
			display: flex;
			flex-direction: column;
			background: #F5F5F5;
			margin-top: -90rpx;
			border-radius: 40rpx;
			height: auto;
			position: relative;
			padding: 30rpx;

			.sort-item {
				display: flex;
				flex-direction: row;
				margin-bottom: 30rpx;
				display: flex;
				justify-content: flex-end;

				.order-item {
					background-color: #E5E5E5;
					margin-left: 20rpx;
					border-radius: 40rpx;
					padding: 10rpx 20rpx;
					font-size: 28rpx;
				}

				.order-item.active {
					background-color: #0056FF;
					color: #fff;
				}
			}

			.tips {
				display: flex;
				flex-direction: row;
				align-items: center;
				padding: 30rpx;
				border-radius: 20rpx;
				margin-bottom: 30rpx;

				.img {
					width: 45rpx;
					height: 45rpx;
					margin-right: 20rpx;
				}

				.text {
					font-size: 32rpx;
					width: calc(100% - 80rpx);

					.total {
						font-weight: bold;
					}
				}
			}

			.info-item {
				height: auto;
				box-shadow: 0 0 10px 0 #dedede;
				background: #fff;
				display: flex;
				flex-direction: column;
				border-radius: 20rpx;
				padding: 30rpx;
				margin-bottom: 30rpx;

				.title-item {
					display: flex;
					flex-direction: row;
					align-items: center;

					.round {
						width: 36rpx;
						height: 36rpx;
						border-radius: 50%;
						margin-top: 12rpx;
						margin-right: 15rpx;
						margin-bottom: 36rpx;
					}

					.name {
						font-weight: bold;
						font-size: 34rpx;
						margin-bottom: 30rpx;
					}
				}


				.progress-block {
					display: flex;
					flex-direction: column;
					background-color: #F5F5F5;
					padding: 30rpx;
					border-radius: 20rpx;

					.name-block {
						display: flex;
						flex-direction: row;
						align-items: center;

						.name {
							font-weight: normal;
							flex-grow: 1;
							font-size: 30rpx;
							margin-bottom: 20rpx;

							.title {
								color: #999;

							}
						}

						.time {
							flex-grow: 0;
							color: #0050FC;
							font-size: 28rpx;
						}
					}

					.phase {
						margin: 10rpx auto;
						height: 40rpx;
						width: 100%;
						position: relative;

						text {
							font-size: 28rpx;
							position: absolute;
							color: #0050FC;
						}
					}
				}

				.amount-list {
					display: flex;
					flex-direction: row;
					justify-content: center;
					align-items: center;

					.amount-item {
						display: flex;
						flex-direction: column;
						margin: 30rpx;

						.money {
							font-weight: bold;
						}

						.text {
							color: #999;
							font-size: 28rpx;
						}
					}

					.thread {
						width: 3rpx;
						height: 40rpx;
						border-radius: 4rpx;
						background-image: linear-gradient(#fff, #999, #fff);
					}
				}
			}
		}
	}
</style>